﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AcademiaInteligenteWeb
{
    public partial class MainMusica_PlayList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                grdMusicaPlayList.DataKeyNames = new string[] { "id" };
                AtualizarGrid();
            }
        }

        protected void lnkExcluir_Click(object sender, EventArgs e)
        {
            new WsAcademiaInteligente.WsAcademiaInteligenteSoapClient().ExcluirMusica_Playlist(Convert.ToInt32(hfCurrentItem.Value));
            AtualizarGrid();
        }

        public void AtualizarGrid()
        {
            grdMusicaPlayList.DataSource = new WsAcademiaInteligente.WsAcademiaInteligenteSoapClient().ListarMusica_Playlist(Convert.ToInt32(Request["id"]));
            grdMusicaPlayList.DataBind();
        }

        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            WsAcademiaInteligente.Musica_Playlist musica = new WsAcademiaInteligente.Musica_Playlist();
            musica.musica = txtMusica.Text;
            musica.id_playlist = Convert.ToInt32(Request["id"]);
            if (!string.IsNullOrEmpty(hfCurrentItem.Value))
            {
                musica.id = Convert.ToInt32(hfCurrentItem.Value);
            }

            if (musica.id > 0)
            {
                new WsAcademiaInteligente.WsAcademiaInteligenteSoapClient().AlterarMusica_Playlist(musica);
            }
            else
            {
                new WsAcademiaInteligente.WsAcademiaInteligenteSoapClient().InserirMusica_Playlist(musica);
            }
            AtualizarGrid();
        }

        protected void lnkAlterar_Click(object sender, EventArgs e)
        {
            WsAcademiaInteligente.Musica_Playlist musica = new WsAcademiaInteligente.WsAcademiaInteligenteSoapClient().SelecionarMusica_PlaylistPorID(Convert.ToInt32(hfCurrentItem.Value));
            txtMusica.Text = musica.musica;
        }
    }
}